package com.teachsys.tms.controller;

import com.teachsys.tms.service.StudentService;
import com.teachsys.tms.entity.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("student")
public class StudentController {

    @Resource
    private  StudentService studentService;
    public Student student=new Student();

    @GetMapping("queryAll")
    public List<Student> queryAll(){
        return this.studentService.queryAll();
    }

    @GetMapping("queryById")
    public Student queryById(String id){
        return this.studentService.queryById(id);
    }

    @GetMapping("insert")
    public Student insert(String name,String sex,String id,String department,String major){
        this.student.setName(name);
        this.student.setSex(sex);
        this.student.setId(id);
        this.student.setDepartment(department);
        this.student.setMajor(major);
        return  this.studentService.insert(this.student);
    }

    @GetMapping("update")
    public Student update(String name,String sex,String id,String department,String major){
        this.student.setName(name);
        this.student.setSex(sex);
        this.student.setId(id);
        this.student.setDepartment(department);
        this.student.setMajor(major);
        return  this.studentService.update(this.student);
    }

    @GetMapping("delete")
    public Boolean delete(String id){
        return this.studentService.delete(id);
    }
}
